

const fs = require('fs');

// check.js - 使用动态导入
async function main() {

    let targetPid = 0

    let WeChatArg = (process.argv[2]);


    const frida = await import('frida');

    // 连接设备
    const device = await frida.getLocalDevice();

    console.log(device.name)

    // 获取进程枚举
    const processes = await device.enumerateProcesses();

    processes.sort((a, b) => a.pid - b.pid);


    // 打印进程信息
    processes.forEach(process => {
        console.log(`- ${process.pid.toString().padEnd(6)} ${process.name}`);
        if (process.parameters && process.parameters.title) {
            console.log(`  窗口标题: ${process.parameters.title}`);
        }

        if (process.name === "uTools.exe") {
            targetPid = 3792
        }
    });

    console.log(targetPid);

    // 通过 PID 附加到进程
    const session = await device.attach(targetPid);
    console.log(`[+] 已成功附加到 PID ${targetPid}`);

    console.log(session);

    const scriptSource = fs.readFileSync("./inject.js", 'utf8');

    const script = await session.createScript(scriptSource);

    await script.load();

    // 在这里可以添加脚本注入逻辑
    console.log("[+] 脚本准备就绪，按 Ctrl+C 退出");
    process.stdin.resume();


}

// 执行主函数
main().catch(console.error);    